package com.roc.steelend.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.roc.steelend.controller.vo.buy.JuanBanBuyOrderVo;
import com.roc.steelend.controller.vo.buy.OtherProductsBuyOrderVo;
import com.roc.steelend.controller.vo.buy.PingBanBuyOrderVo;
import com.roc.steelend.controller.vo.common.BuyByRecoding;
import com.roc.steelend.controller.vo.returnformat.ReturnMsg;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.service.BuyOrderService;
import com.roc.steelend.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "采购订单功能接口")
public class BuyOrderController {


    @Autowired
    private BuyOrderService buyOrderService;

    @PostMapping("/v1/buy/pingban")
    @ApiOperation(value = "采购平板提交接口",notes = "需要一个所有信息的类")
    public ReturnMsg buyPingBan(@RequestBody PingBanBuyOrderVo pingBanBuyOrderVo, HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();

        return buyOrderService.addBuyPingBanOrderService(pingBanBuyOrderVo, Integer.valueOf(employeeIdAsString));
    }


    @PostMapping("/v1/buy/juanban")
    @ApiOperation(value = "采购卷板提交接口",notes = "需要一个所有信息的类")
    public ReturnMsg buyJuanBan(@RequestBody JuanBanBuyOrderVo juanBanBuyOrderVo, HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();

        return  buyOrderService.addBuyJuanBanOrderService(juanBanBuyOrderVo,Integer.valueOf(employeeIdAsString));
    }

    @PostMapping("/v1/buy/otherproducts")
    @ApiOperation(value = "采购其他产品提交接口",notes = "需要一个所有信息的类")
    public ReturnMsg buyOtherProducts(@RequestBody OtherProductsBuyOrderVo otherProductsBuyOrderVo, HttpServletRequest request){
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return buyOrderService.addBuyOtherProductsOrderService(otherProductsBuyOrderVo,Integer.valueOf(employeeIdAsString));
    }



//
    @PostMapping("/v1/buy/find/recording")
    @ApiOperation(value = "采购查询接口(ps:特殊情况使用post,但不修改数据!!!)",notes = "可选择性填一个所有信息查询器的类(ps:特殊情况使用post,但不修改数据!!!)")
    private ReturnMsgForTable buyFindRecoding( @RequestBody(required = false)@ApiParam(value = "条件选择器类",required = false) BuyByRecoding selectMsg){
        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setCurrenPage(selectMsg.getCurrentPage());
        returnMsgForTable.setObjectList( buyOrderService.buyFindRecoding(selectMsg));
        returnMsgForTable.setTotal(buyOrderService.buyFindRecodingCount(selectMsg));
        return returnMsgForTable;
    }









}
